package com.ytsky.hctechnologysys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ytsky.hctechnologysys.dao.EducateMapper;
import com.ytsky.hctechnologysys.entity.Educate;
import com.ytsky.hctechnologysys.service.EducateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Dell
 */
@Service
public class EducateServiceImpl implements EducateService {

    @Autowired
    private EducateMapper educateMapper;

    @Override
    public boolean append(Educate educate) {
        return educateMapper.insert(educate) > 0;
    }

    @Override
    public Educate findByNamePass(String username, String password){

        return  educateMapper.selectByNamePass(username,password);
    }


    @Override
    public PageInfo<Educate> findAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        final List<Educate> educates = educateMapper.selectAll();
        PageInfo<Educate> pageInfo = new PageInfo<>(educates);
        return pageInfo;
    }

    @Override
    public PageInfo<Educate> findByKeyword(int pageNum, int pageSize, String keyword) {
        PageHelper.startPage(pageNum,pageSize);
        List<Educate> educates = educateMapper.selectByKeyword(keyword);
        PageInfo<Educate>  pageInfo = new PageInfo<>(educates);
        return pageInfo;
    }

    @Override
    public Educate findById(int id) {
        return educateMapper.selectById(id);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean modify(Educate educate) {
        return educateMapper.updateById(educate) > 0;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean remove(int id) {
        return educateMapper.deleteById(id) > 0;
    }
}
